#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
from typing import Dict, Any, Optional, List


class Config:
    """
    统一配置类，包含NebulaGraph、Milvus、SQLite的配置，以及嵌入模型和LLM的API密钥
    """

    def __init__(self):
        # NebulaGraph配置
        self.nebula_config = {
            "ip": os.environ.get("NEBULA_IP", "114.132.92.57"),
            "port": int(os.environ.get("NEBULA_PORT", "9669")),
            "user": os.environ.get("NEBULA_USER", "whrdckf3"),
            "password": os.environ.get("NEBULA_PASSWORD", "WhRdcKf3!!!"),
            "space": os.environ.get("NEBULA_SPACE", "projectx")
        }

        # 向量存储类型
        self.vector_store_type = os.environ.get("VECTOR_STORE_TYPE", "milvus")

        # SQLite配置
        self.sqlite_config = {
            "db_path": os.environ.get("SQLITE_DB_PATH", "vector_store.db")
        }

        # Milvus配置
        self.milvus_config = {
            # Milvus服务器连接
            "uri": os.environ.get("MILVUS_URI", "http://114.132.92.57:19530"),
            "token": os.environ.get("MILVUS_TOKEN", "root:WhRdcKf3!!!"),
            # Milvus Lite本地连接
            "db_path": os.environ.get("MILVUS_DB_PATH", "milvus_store.db"),
            "collection_name": os.environ.get("MILVUS_COLLECTION", "node_vectors"),
            "dimension": int(os.environ.get("MILVUS_DIMENSION", "1024"))
        }

        # 嵌入模型配置
        self.embedding_config = {
            "model_name": os.environ.get("EMBEDDING_MODEL", "BAAI/bge-m3"),
            "api_key": os.environ.get("EMBEDDING_API_KEY", "sk-sttkzgppyhkmcgbuasbvxbkddqavqthpictybjmmewfalbfv"),
            "api_base": os.environ.get("EMBEDDING_API_BASE", "https://api.siliconflow.cn/v1")
        }

        # LLM配置
        self.llm_config = {
            "model": os.environ.get("LLM_MODEL", "deepseek-chat"),
            "api_key": os.environ.get("LLM_API_KEY", "sk-7624b89d26db4755ab2977a594dfdc6d"),
            "api_base": os.environ.get("LLM_API_BASE", "https://api.deepseek.com/v1")
        }

    def get_nebula_config(self) -> Dict[str, Any]:
        """获取NebulaGraph配置"""
        return self.nebula_config

    def get_vector_store_config(self) -> Dict[str, Any]:
        """根据配置的存储类型返回对应的向量存储配置"""
        if self.vector_store_type == "sqlite":
            return self.sqlite_config
        elif self.vector_store_type == "milvus":
            return self.milvus_config
        else:
            raise ValueError(f"不支持的向量存储类型: {self.vector_store_type}")

    def get_embedding_config(self) -> Dict[str, Any]:
        """获取嵌入模型配置"""
        return self.embedding_config

    def get_llm_config(self) -> Dict[str, Any]:
        """获取LLM配置"""
        return self.llm_config

    def as_dict(self) -> Dict[str, Any]:
        """将所有配置转换为字典"""
        return {
            "nebula_config": self.nebula_config,
            "vector_store_type": self.vector_store_type,
            "sqlite_config": self.sqlite_config,
            "milvus_config": self.milvus_config,
            "embedding_config": self.embedding_config,
            "llm_config": self.llm_config
        }


# 全局配置实例
config = Config() 